<?php

class App_Methods_Request_RemoveUserGroup {

  /**
   *
   * @var App_Methods_Data_App
   */
  public $app;
	public $userGroupId;

  public function __construct($params) {
    $this->app = new App_Methods_Data_App($params->app);
    $this->userGroupId = $params->userGroupId;
  }

  public function process() {
    if (!Core_Auth::getInstance()->getUser()->isAdmin())
    	throw new App_Exception_App(4000);
    
    $userGroupBase = UserGroupsQuery::create()->findOneByBasic(1);
    
    $con = Propel::getConnection();
    $con->beginTransaction();
    try {
	    UsersQuery::create()
	    ->filterByUserGroupId($this->userGroupId)
	    ->update(array('UserGroupId' => $userGroupBase->getId()), $con);
	    UserGroupsQuery::create()
	    ->filterById($this->userGroupId)
	    ->delete($con);
	    $con->commit();
    } catch(Exception $e) {
    	$con->rollBack();
    	throw $e;
    }
    
    return new App_Methods_Response_RemoveUserGroup(true);
  }

}